import "package:flutter/material.dart";
import 'package:flutter/rendering.dart';
import 'package:flutter_pink_app/composables/icon_text_match.dart';
import 'package:flutter_pink_app/serialized/recommend.dart';
import 'package:flutter_pink_app/style/text.dart';
import 'package:flutter_pink_app/util.dart';

// 视频详情页文字pannel组合
class VideoInfoPanel extends StatefulWidget {
  final VideoInfo _info;
  const VideoInfoPanel(this._info, {Key key}) : super(key: key);

  @override
  _VideoInfoPanelState createState() => _VideoInfoPanelState();
}

class _VideoInfoPanelState extends State<VideoInfoPanel> {
  bool _isCollapse = true; // 是否折叠

  _VideoInfoPanelState();

  // 构建次级详情方法
  Padding _buildSubDetail() {
    final int view = widget._info.view; // 观看次数
    final int reply = widget._info.reply; // 弹幕数
    final String date = widget._info.createTime; // 创建时间
    return Padding(
      padding: const EdgeInsets.only(top: 8),
      child: Row(
        children: <IconTextMatch>[
          IconTextMatch(
              text: formatPlayCount(view), icon: Icons.ondemand_video),
          IconTextMatch(text: reply.toString(), icon: Icons.list_alt),
          IconTextMatch(text: date)
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return ExpansionTile(
      key: widget.key,
      onExpansionChanged: (isExpanding) =>
          setState(() => _isCollapse = !isExpanding),
      initiallyExpanded: !_isCollapse,
      /// 原
      title: Text(widget._info.title,
          style: videoTitleStyle,
          softWrap: true,
          overflow: _isCollapse ? TextOverflow.ellipsis : null),
      subtitle: _buildSubDetail(),
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 15),
          child: Text(widget._info.desc, style: normalGrayStyle),
        )
      ],
      // leading: Text('leading'*19),
    );
  }
}
